<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">
    <script th:src="@{|/jquery/jquery.md5.js|}"></script>
    <link rel="stylesheet" th:href="@{../bootstrap/css/bootstrap.min.css}">
    <link rel="stylesheet" th:href="@{../css/font-awesome.min.css}">
    <link rel="stylesheet" th:href="@{../css/main.css}">
    <script th:src="@{../jquery/jquery-2.1.1.min.js}"></script>
    <script th:src="@{|/jquery/jquery.md5.js|}"></script>
    <script th:src="@{../bootstrap/js/bootstrap.min.js}"></script>
    <script th:src="@{../script/docs.min.js}"></script>
    <script th:src="@{../layer/layer.js}"></script>
    <style>
        .tree li {
            list-style-type: none;
            cursor:pointer;
        }
        table tbody tr:nth-child(odd){background:#F4F4F4;}
        table tbody td:nth-child(even){color:#C00;}
    </style>
</head>

<body>


<div th:replace="../templates/nav"></div>
<div class="container-fluid">
    <div class="row">
        <div th:replace="../templates/menu"></div>
        <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title"><i class="glyphicon glyphicon-th"></i> 数据列表</h3>
                </div>
                <div class="panel-body">
                    <form class="form-inline" role="form" style="float:left;">
                        <div class="form-group">
                            <label >审批状态</label>
                            <select name="wstate" id="wstate" class="form-control" placeholder="请选择地区">
                                <option  value="">请选择审核状态</option>
                                <option value="未审核">未审核</option>
                                <option value="已审核">已审核</option>
                                </option>
                            </select>
                        </div>
                        <button type="button" class="btn btn-warning" id="btnSearch"><i class="glyphicon glyphicon-search"></i> 查询</button>
                    </form>
                    <br>
                    <hr style="clear:both;">
                    <div class="table-responsive">
                        <table class="table  table-bordered">
                            <thead>
                            <tr >
                                <th width="30">NO.</th>
                                <th>申请人</th>
                                <th>加班地区</th>
                                <th>开始时间</th>
                                <th>结束时间</th>
                                <th>时长</th>
                                <th>申请时间</th>
                                <th>审核状态</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody id="tbody">

                            </tbody>
                            <tfoot>
                            <tr >
                                <td colspan="9" align="center">
                                    <ul class="pagination" id="byPage">

                                    </ul>
                                </td>
                            </tr>

                            </tfoot>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>


<script type="text/javascript">
    $(function () {
        $(".list-group-item").click(function(){
            if ( $(this).find("ul") ) {
                $(this).toggleClass("tree-closed");
                if ( $(this).hasClass("tree-closed") ) {
                    $("ul", this).hide("fast");
                } else {
                    $("ul", this).show("fast");
                }
            }
        });
        showList(1);
    });
    $("#btnSearch").click(function(){
        showList(1);
    });
    //审核
    function edit(wno){
        url="/EduManage/toUpdateWstateDo";
        var da={"wno":wno}
        $.get(url,da,function (data){
            if (data.result){
                layer.msg("审核成功！！！", {time: 1000, icon: 6, shift: 6}, function () {
                    location.href="/EduManage/workaudit"
                });

            }
        })
    }
    //查询条件查询
    function showList(currentPage){
        $.ajax({
            url:"/EduManage/workauditDo",
            type:"post",
            data:{"currentPage":currentPage,
                "wstate":$("#wstate").val()},
            success:function(data){
                if(data.result){
                    var str="";
                    $.each(data.workList,function(index,work){
                        str += "<tr>";
                        str += "<td>"+(index+1)+"</td>";
                        str += "<td>"+work.name+"</td>";
                        str += "<td>"+work.address+"</td>";
                        str += "<td>"+work.btime+"</td>";
                        str += "<td>"+work.etime+"</td>";
                        str += "<td>"+work.time+"</td>";
                        str += "<td>"+work.nowtime+"</td>";
                        str += "<td>"+work.wstate+"</td>";
                        //判断审核状态是否为"未审核"，如果为"未审核"将会出现审批按钮进行审批操作
                        if(work.wstate=="未审核"){
                            str+="<td>";
                            str += "<button type='button' class='btn btn-primary btn-xs' onclick='edit("+ work.wno+")'>审批</button>"
                            str+="</td>";
                        }
                        if(work.wstate=="已审核"){
                            str+="<td>";
                            str += "<button type='button' disabled='disabled' class='btn btn-primary btn-xs' >审批</button>"
                            str+="</td>";
                        }
                        str += "</tr>";
                    });
                    $("#tbody").html(str);
                    var pageStr = "";
                    pageStr += '<li class="'+(data.pageBean.currentPage==1?'disabled':'')+'"><a href="#" onclick="showList('+(data.pageBean.currentPage-1)+')">上一页</a></li>';
                    for(var i=1;i<=data.pageBean.countPage;i++) {
                        pageStr += '<li class="'+(data.pageBean.currentPage==i?'active':'')+'"><a href="#" onclick="showList('+i+')">'+i+'<span class="sr-only">(current)</span></a></li>';
                    }
                    pageStr += '<li class="' + (data.pageBean.currentPage == data.pageBean.countPage ? 'disabled' : '') + '"><a href="#" onclick="showList('+(data.pageBean.currentPage==data.pageBean.countPage?data.pageBean.countPage:data.pageBean.currentPage+1)+')">下一页</a></li>';
                    $("#byPage").html(pageStr);
                }
            }
        });
    }

    laydate.render({
        elem: '#test5'
        ,type: 'datetime'
    });


</script>
</body>
</html>